<?php

class Model_App_Apply extends PhalApi_Model_NotORM {
    protected function getTableName($id) {
        return 'apply';
    }

    /**
     * 报名表中添加一条数据
     * @author wizarhuang
     * @since 2015-07-21
     * @param $data
     * @return mixed
     */
    public function insertUser($data) {
        return DI()->notorm
            ->apply
            ->insert($data);
    }
    /**
     *根据 OPENID 删除项目表中的一条数据
     *  int openid
     */
    public function deleteApplyByOpenid($apply_id){
        return DI()->notorm
            ->apply
            ->where('apply_id = ?', $apply_id)
            ->delete();
    }

    /**
     * 检查是否重复
     * @param  string $apply_id
     */
    public function checkApplyDuplicate($data) {
        return DI()->notorm
            ->apply
            ->where('apply_id = ?', $data['apply_id'])
            ->fetchRow();
    }
    /**
     * 通过 apply_id 查询 一条相应数据
     */
    public function getApplyByApplyId($apply_id){
        return DI()->notorm
            ->apply
            ->where('apply_id = ?',$apply_id)
            ->fetchOne();
    }
    /**
     * 查询客户资料列表
     *
     */
    public function getApplyList(){
        return DI()->notorm
            ->apply
            ->fetchAll();
    }
    /**
     * 根据openid
     * 更新客户资料
     */
    public function edit($data,$apply_id){
        return DI()->notorm
            ->apply
            ->where('apply_id = ?',$apply_id)
            ->update($data);
    }


    /**
     * 检查 admin (openid) 是否存在
     */
    public function checkProjectOpenid($data){
        return DI()->notorm
            ->apply
            ->where('apply_id = ?', $data['admin'])
            ->fetchOne();
    }
}
